package com.hsj.goldstore.mvp.view;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.content.Loader;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.hsj.goldstore.R;
import com.hsj.goldstore.base.BaseMvpActivity;
import com.hsj.goldstore.base.PresenterFactory;
import com.hsj.goldstore.base.PresenterLoader;
import com.hsj.goldstore.mvp.present.RegisterPresent;
import com.hsj.goldstore.utils.ActivityCollector;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/3/25.
 */

public class ForgetPasswordActivity extends BaseMvpActivity<RegisterPresent, RegistView> implements RegistView {
    @BindView(R.id.btn_back)
    ImageView btnBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.btn_right)
    TextView btnRight;
    @BindView(R.id.et_phone)
    EditText etPhone;
    @BindView(R.id.et_verification_code)
    EditText etVerificationCode;
    @BindView(R.id.tv_verification_code)
    TextView tvVerificationCode;
    @BindView(R.id.et_pwd)
    EditText etPwd;
    @BindView(R.id.et_pwd_again)
    EditText etPwdAgain;


    @Override
    protected int getResouseId() {
        return R.layout.activity_forget_password;
    }

    @Override
    protected void initView() {
        tvTitle.setText(getString(R.string.forget_the_password));
        btnRight.setVisibility(View.GONE);

    }

    @Override
    protected void initData() {
        presenter.init();
    }

    @Override
    public Loader<RegisterPresent> onCreateLoader(int id, Bundle args) {
        return new PresenterLoader<>(this, new PresenterFactory<RegisterPresent>() {
            @Override
            public RegisterPresent create() {
                return new RegisterPresent();
            }
        });
    }

    @Override
    public String getPhone() {
        return etPhone.getText().toString().trim();
    }

    @Override
    public String getVerificatonCode() {
        return etVerificationCode.getText().toString().trim();
    }

    @Override
    public void setVerificationCodeEnable(boolean enable) {
        tvVerificationCode.setEnabled(enable);
    }

    @Override
    public String getPwd() {
        return etPwd.getText().toString().trim();
    }

    @Override
    public String getPwdAgain() {
        return etPwdAgain.getText().toString().trim();
    }

    @Override
    public void setVerificationText(String number) {
        tvVerificationCode.setText(number);
    }

    @Override
    public boolean hasRead() {
        return false;
    }


    @Override
    public void gotoMainActivity() {
        finish();
//        ActivityCollector.removeAllActivity();
//        MainActivity.getIntantce(this, MainActivity.class);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.btn_back, R.id.tv_verification_code, R.id.btn_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_back:
                finish();
                break;
            case R.id.tv_verification_code:
                presenter.sendVerificationCode();
                break;
            case R.id.btn_submit:
                presenter.forgetPassword();
                break;
        }
    }
}
